
* Set directories

cd /Users/xiaosongw/Dropbox/Research/InformedSources/ReplicationRemove2

*------------------ Figure 1: Price cycle examples from 2015 -----------------*

* Load data
use ./Data/is_mel_p_2005_2019, clear
keep if t>=td(1may2015) & t<=td(15jun2015)

* Compute mean price by market, brand, date
sort bid t
collapse (mean) p c, by(bid t)

* Dates for xlabels
local xt1=td(1may2015)
local xt2=td(1may2015)+15
local xt3=td(1may2015)+30
local xt4=td(1may2015)+45

* Arrows for plots
local y1=140
local y2=140
local x1=td(11may2015)
local x2=td(13may2015)
local xtext1=td(8may2015)+0.25

local y3=140
local y4=140
local x3=td(24may2015)
local x4=td(22may2015)
local xtext2=td(27may2015)

local y5=131
local y6=129
local x5=td(2jun2015)+0.5
local x6=td(3jun2015)+0.5
local xtext3=td(1jun2015)

local y9=143
local y10=144.5
local x9=td(4jun2015)
local x10=td(5jun2015)
local y11=140.5
local y12=139
local x11=td(4jun2015)
local x12=td(5jun2015)
local xtext4=td(2jun2015)

* Plot example cycle from Melbourne
twoway 	(line p t if bid==1, lwidth(medthick)   connect(stairstep) lcolor(green)  lpattern(dash)) ///
		(line p t if bid==2, lwidth(thin)   connect(stairstep) lcolor(blue)   lpattern(shortdash) ) ///
		(line p t if bid==3, lwidth(medium)   connect(stairstep) lcolor(red) lpattern(solid)) ///
		(line p t if bid==4, lwidth(thin) connect(stairstep) lcolor(purple)  lpattern(dash_dot) ) ///
		(line p t if bid==5, lwidth(thin)   connect(stairstep) lcolor(orange) lpattern(longdash)) ///		
		(line c t if bid==1, lwidth(medthick) connect(stairstep) lcolor(gs0) lpattern(shortdash)  ///		
		ytitle("Mean Daily Station-Level Retail Price (cpl)", height(6)) ylabel(125(10)155, labsize(*0.8) grid gmin gmax) ///
		xtitle(" ", height(6)) ///
		xlabel(`xt1' `" "May 1"  "2015" "' `xt2' `" "May 15"  "2015" "' `xt3' `" "June 1"  "2015" "' `xt4' `" "June 15"  "2015" "', labsize(*0.55)) ///
		plotregion(margin(zero) style(none) fcolor(white)) graphregion(color(white)) bgcolor(white) ///
		legend(order(1 2 3 4 5 6) ring(0) size(*0.75) position(12) symx(*0.5) region(lwidth(*0.05)) rows(1) ///
		label(1 "BP") label(2 "Caltex") label(3 "Coles") label(4 "Woolworths") label(5 "7-Eleven") label(6 "Wholesale" "TGP"))) ///
		(pcarrowi `y1' `x1' `y2' `x2', color(black) lwidth(*1) barbsize(1) msize(2) ///
		text(140 `xtext1' "Restoration" "phase", justification(right) size(*0.7))) ///
 		(pcarrowi `y3' `x3' `y4' `x4', color(black) lwidth(*1) barbsize(1) msize(2) ///
		text(140 `xtext2' "Undercutting" "phase", justification(left) size(*0.7))) ///	
 		(scatter p t if (bid==1 | bid==2 | bid==3 | bid==4 | bid==5) & t==td(12may2015), mcolor(black%15) msize(*1.1) msymbol(circle)) ///
		(scatter p t if (bid==1 | bid==2 | bid==3 | bid==4 | bid==5) & t==td(4jun2015), mcolor(black%15) msize(*1.1) msymbol(circle)) ///
		(pcarrowi `y5' `x5' `y6' `x6', color(black) lwidth(*1) barbsize(1) msize(2) ///
		text(132 `xtext3' "Restoration" "price {bf:signals}", justification(center) size(*0.6)) ///
		text(142 `xtext4' "Restoration" "{bf:consolidation}", justification(right) size(*0.6))) ///
		(pcarrowi `y9' `x9' `y10' `x10', color(black) lwidth(*1) barbsize(1) msize(2)) ///
		(pcarrowi `y11' `x11' `y12' `x12', color(black) lwidth(*1) barbsize(1) msize(2))		
graph export Output/fig1_example.pdf, as(pdf) replace
